@extends('home.seller.layout.index')

@section('content')
	<div class="mws-panel grid_8">
    	<div class="mws-panel-header">
        	<span><i class="icon-table"></i> 修改商品信息</span>
        </div>
        <div class="mws-panel-body no-padding">
        	<form id="mws-validate" class="mws-form" action="/home/seller/goods/update?id={{ $data1['id'] }}" novalidate="novalidate" method="post" enctype="multipart/form-data">
            	{{ csrf_field() }}
            	<div id="mws-validate-error" class="mws-form-message error" style="display:none;"></div>
            	<div class="mws-form-inline">
                	<div class="mws-form-row">
                    	<label class="mws-form-label">商品标题</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="goodsname" class="required large" value="{{ $data1['goodsname'] }}" placeholder="请输入商品的标题（用于搜索商品）">
                        </div>
                    </div>
                	<div class="mws-form-row">
                    	<label class="mws-form-label">商品详情介绍</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="details" class="required email large" value="{{ $data2['details'] }}" placeholder="请输入商品详情介绍">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品名称</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="title" class="required email large" value="{{ $data2['title'] }}" placeholder="请输入商品名称">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品价格</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="price" class="required digits large" value="{{ $data1['price'] }}" placeholder="请输入价格，必须输入整数">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品数量</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="inventory" class="required digits large" value="{{ $data1['inventory'] }}" placeholder="请输入商品的数量，必须输入整数">
                        </div>
                    </div>
                    <div class="mws-form-row">
                        <div class="mws-form-cols">
                            <div class="mws-form-col-4-8">
                                <label class="mws-form-label">商品属性（最多5种属性）例如：颜色、大小、重量等</label>
                                @for($i=0;$i<5;$i++)
	                                @if($b[$i][0] != null)
		                                <div class="mws-form-item" id="attrbute_key{{ $i+1 }}">
		                                    <input type="text" style="margin-top:5px" name="attrbute_key{{ $i+1 }}" value="{{ $b[$i][0] }}" placeholder="请输入商品的属性1">
		                                </div>
		                            @endif
                                @endfor
                            </div>
                            <div class="mws-form-col-4-8" id="attr_a">
                                <label class="mws-form-label">属性值</label>
                                @for($i=0;$i<5;$i++)
	                                @if($b[$i][1] != null)
		                                <div class="mws-form-item" id="attrbute_val{{ $i+1 }}">
		                                    <input type="text" style="margin-top:5px" name="attrbute_val{{ $i+1 }}" value="{{ $b[$i][1] }}" placeholder="请输入商品的属性1的值">
		                                </div>
	                                @endif
                                @endfor
                            </div>
                        </div>
                         <div class="mws-form-cols">
	                        <div class="mws-form-col-7-8">
	                            <label class="mws-form-label"></label>
	                        </div>
                            <div class="mws-form-col-1-8">
                            	<button data-toggle="dropdown" class="btn btn-warning dropdown-toggle" aria-expanded="true" style="margin-top:5px" id="attrbute_add" onclick="myadd(this)">添加属性</button>
                            </div>
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品分类</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="classname" value="" class="required digits large" placeholder="{{ $classname }}(不能修改)" disabled>
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品头像</label>
                    	<div class="mws-form-item">
                        	<img src="{{ $data1['picture'] }}" alt="" style="height:100px;">
                        </div>
						<div class="mws-form-item" style="margin-top:5px">
                        <input type="file" name="picture"  value="" onclick="return confirm('确认修改商品头像吗？')">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品详情图</label>
                    	<div class="mws-form-item">
                        	<img src="{{ $data2['image1'] }}" alt="" style="height:100px;">
                        	<img src="{{ $data2['image2'] }}" alt="" style="height:100px;">
                        	<img src="{{ $data2['image3'] }}" alt="" style="height:100px;">
                        	<img src="{{ $data2['image4'] }}" alt="" style="height:100px;">
                        	<img src="{{ $data2['image5'] }}" alt="" style="height:100px;">
                        </div>
                        <div class="mws-form-item" style="margin-top:5px">
                        	<button type="button" class="btn btn-warning" onclick="edit(this)">修改商品详情图</button>
                        </div>
                        <div class="mws-form-item" style="display:none">
                        	<script id="container" name="content" type="text/plain" style="width:100%">
						        
						    </script>
                   		</div>
                    </div>
                </div>
                <div class="mws-button-row">
                	<input type="submit" class="btn btn-danger" value="修改">
                </div>
            </form>
        </div>    	
    </div>
@endsection

@section('script')
	<script>
    	// 添加属性
	    var count = $('#attr_a div').length;
	    // console.log(count)
		function myadd() {
			if (count < 5) {
				count++;
				// console.log(count)
				$('#attrbute_key'+(count-1)).after('<div class="mws-form-item" id="attrbute_key'+count+'"><input type="text" style="margin-top:5px" name="attrbute_key'+count+'" value="" placeholder="请输入商品的属性'+count+'"></div>');
				$('#attrbute_val'+(count-1)).after('<div class="mws-form-item" id="attrbute_val'+count+'"><input type="text" style="margin-top:5px" name="attrbute_val'+count+'" value="" placeholder="请输入商品的属性'+count+'的值"></div>');
				

			} else {
				$('#attrbute_add').fadeOut('slow');
				return;
			}
		}

		// 修改详情图
		function edit(but) {
			var ab = confirm('确认修改商品详情图吗？');
			if (ab) {
				$(but).parent().next().css('display','block');
			}
		}
    </script>
	<!-- 配置文件 -->
    <script type="text/javascript" src="/homeassets/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/homeassets/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container');
    </script>
@endsection